<?php
class Shell_Command_Cat extends Shell_Command_Abstract_CommandBase implements Shell_Command_Abstract_IShellCommand
{
	public function __construct()
	{
		parent::__construct();
		$this->NAME = "cat";	
	}
	
//*************************************************************************************************
	public function execute($arguments) 
	{
		parent::execute($arguments);
		
		// try to parse the command line options, terminate command's execution if options were incorrect
		if ( $this->parseOptions() === false )
			return;
		
		$args = $this->options->getRemainingArgs();
		
		if ( count($args) == 0)
		{
			echo "\nNothing to display. Please, try \"cat --help\"\n";
			return;
		}
				 
		$fileName = $args[0];
				
		$fs = Core_Registry::read(Enum_RegistryItems::FILE_SYSTEM);	
		$fileRealPath = $fs->getRealPath($fileName);
		
		if ($fileRealPath === false)
		{
			echo "\n$fileName does not exist.\n";
			return;
		}
		
		$content =   file_get_contents($fileRealPath);
		echo "\n" . $content . "\n\n"; 
		
	}
}